package com.atguigu.rabbitmq.work;

import com.atguigu.rabbitmq.util.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author 杨林
 * @create 2022-10-06 14:53 星期四
 * description:work模式下的生产者
 */
public class Producer {

    public static void main(String[] args) throws IOException, TimeoutException {
        //获取连接
        Connection connection = ConnectionUtil.getConnection();
        //创建channel
        Channel channel = connection.createChannel();
        channel.queueDeclare("work_queue",true, false, false, null);
        //生产10条消息
        for (int i = 0; i < 10; i++) {
            String msg = "你好  世界" + i;
            channel.basicPublish("","work_queue",null,msg.getBytes());
        }
        channel.close();
        connection.close();
    }
}
